package com.rex.saas.job;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.rex.saas.db.entity.SaasDeviceInfo;
import com.rex.saas.service.DeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class SyncDeviceInfoJob {
    @Autowired
    private DeviceService deviceService;

    private static final Cache<String, String> deviceCategoryCache = Caffeine.newBuilder()
            .expireAfterWrite(1, TimeUnit.DAYS)
            .maximumSize(1000)
            .build();

//    @Scheduled(cron = "0 1/1 * * * ?") // 每
//    public void syncDeviceCategory() {
//        List<SaasDeviceInfo> list = deviceService.alllist();
//        list.forEach(deviceInfo -> {
//            deviceCategoryCache.put(deviceInfo.getDeviceName(), deviceInfo.getCategoryName());
//        });
//        log.info("SyncDeviceInfoJob syncProfileInfo end, time：{}", new Date());
//    }
}
